package com.qf.utils;//package com.qf.springbootcrud.utils;
//
//import com.alibaba.fastjson.JSONObject;
//import com.alipay.api.AlipayApiException;
//import com.alipay.api.AlipayClient;
//import com.alipay.api.DefaultAlipayClient;
//import com.alipay.api.internal.util.AlipaySignature;
//import com.alipay.api.request.AlipayTradePagePayRequest;
//import com.qf.springbootcrud.pojo.TbSeckillOrder;
//import org.springframework.stereotype.Component;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Set;
//import java.util.UUID;
//
//@RequestMapping("/pay")
//@RestController
//@Component
///**
// * 支付宝支付
// */
//public class AliPayUtils {
//
//    private static final String privateKey="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDP6pIJg4q3kCt36e/JKshSfeeL0xQE+0R2WAYP5SODeeGiY1Arb4ZE0R5i84bRZQNv9hVWJ7gT8f91ae2kGNJF5Iq3LocMQjC1WZSu68cjIk6xYusc+RGDooC84TorhOMBCrdySyE0rIf/3xV1/ymakm7fKj0PuHv0UpkWmFXnHPAHifyNh9VgbpZxoItCSplfVOGErsSJouLVfiNzpqKyi+CYCdLoKHoiEdWAo64C6FESiKQOOnnhAtyUKdgRUa/lpGEjsI1NIzWoXRRqM2D1bI6nUOYhL6UIc/Cq9Cs5KPeT+PIO3Lsc6rRuBEHjx2vlAgTw0qR2E28jqQlnfvJzAgMBAAECggEBAMxuAYUlN2Fhebv/4mrTi//AF8idlBOJ0zjhN6StUgvV7Qqzx4HNuCE11EDK3YZJYeXV+giqKQ5DZUBXFPfCCA38tn+CWfqtoiLNn6mV3kknVGSJtE7afmQFhbsxYPalRGYj2Vehk1atRVNKT1mjt45p6GW4rC0m4YnLJQbYZa5EOXFaMGe7LpGRC/FESVkOuD2x0jmuWZoZg29uZqdI9VmT7PfDHDs4aVOzL15xe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21uo4BibGhTK2ls3UjD5lb+8D4n6bqndWAdD4wT0//NZ2cAH0sJF6wQnuhnds3GQQQlGCptPUbWPox00uXrIMNJUQpMvJNnn2nVFJZrw5U6pDbZkwB8s7aDxLI8/vlMWQzXENgqIY4y7PimNuMJIPu3WPc9lU+uIv2znQeIDWjVqYnS/0gJAu0HIKWLEfD/2jKMj3EmOJk5Gg+JycDgpJkt+IgNUC2IqhDq77DCfJNB1vE1wHR/JvI/o47KYvIU91UcBTlKxNFpKsS5KESSyqN9YZXAPuJyij4JHXMPfqnDcsWWRstCAwqM4EC2cBwHpWJkskKEOF1G6MwIDAQAB";
//    private static final String serverUrl="https://openapi.alipaydev.com/gateway.do";
//    private static final String appId="2021000121677421";
//    private static final String format="json";
//    private static final String signType="RSA2";
//    private static final String charset="utf-8";
//    private static final String returnUrl="";
//    private static final String notifyUrl="https://60m3x12825.zicp.fun/notifyUrl";
//
//
//    public static String createAlipayFrom(TbSeckillOrder tbSeckillOrder){
//        AlipayClient alipayClient =  new DefaultAlipayClient( serverUrl , appId, privateKey, format, charset, alipayPublicKey, signType);  //获得初始化的AlipayClient
//        AlipayTradePagePayRequest alipayRequest =  new  AlipayTradePagePayRequest(); //创建API对应的request
////            alipayRequest.setReturnUrl( "http://localhost:8080/#/success" );
//        alipayRequest.setReturnUrl( "http://182.92.6.209:8088/#/success" );
//
//        alipayRequest.setNotifyUrl(notifyUrl); //在公共参数中设置回跳和通知地址
////      声明需要支付的对象
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("out_trade_no", tbSeckillOrder.getTransactionId());
//        jsonObject.put("product_code", "FAST_INSTANT_TRADE_PAY");
//        jsonObject.put("total_amount", tbSeckillOrder.getMoney());
//        jsonObject.put("subject", "秒杀商品购买");
//        jsonObject.put("body", "秒杀商品购买");
//        alipayRequest.setBizContent(jsonObject.toJSONString()); //填充业务参数
//        String form= "" ;
//        try  {
//            form = alipayClient.pageExecute(alipayRequest).getBody();  //调用SDK生成表单
//        }  catch  (AlipayApiException e) {
//            e.printStackTrace();
//        }
//        return form;
//    }
//
//    public static Map verifyAlipayRequest(HttpServletRequest httpServletRequest){
////        将request请求解析为map集合
//        Map<String, String> stringStringMap = convertRequestParamsToMap(httpServletRequest);
//        try {
////            使用公钥进行解密操作
//            boolean signVerified = AlipaySignature.rsaCheckV1(stringStringMap, alipayPublicKey, charset, signType); //调用SDK验证签名
//            if (signVerified){
////                如果为true
//                return stringStringMap;
//            }
//        } catch (AlipayApiException e) {
//            e.printStackTrace();
//        }
//
//        return null;
//    }
//
//    // 将request中的参数转换成Map
//    private static Map<String, String> convertRequestParamsToMap(HttpServletRequest request) {
//        Map<String, String> retMap = new HashMap<String, String>();
//
//        Set<Map.Entry<String, String[]>> entrySet = request.getParameterMap().entrySet();
//
//        for (Map.Entry<String, String[]> entry : entrySet) {
//            String name = entry.getKey();
//            String[] values = entry.getValue();
//            int valLen = values.length;
//
//            if (valLen == 1) {
//                retMap.put(name, values[0]);
//            } else if (valLen > 1) {
//                StringBuilder sb = new StringBuilder();
//                for (String val : values) {
//                    sb.append(",").append(val);
//                }
//                retMap.put(name, sb.toString().substring(1));
//            } else {
//                retMap.put(name, "");
//            }
//        }
//
//        return retMap;
//    }
//
//}
